package org.yzh.scheduler.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yzh.commons.model.APIResult;
import org.yzh.commons.model.PageInfo;
import org.yzh.commons.model.Pagination;
import org.yzh.scheduler.model.entity.JobLogDO;
import org.yzh.scheduler.service.JobLogService;

import java.time.LocalDateTime;

@ApiResponses(value = {
        @ApiResponse(code = 400, message = "请求参数有误", response = APIResult.class),
        @ApiResponse(code = 500, message = "服务器异常", response = APIResult.class)}
)
@Api(description = "任务日志API")
@RequestMapping("job-log")
@RestController
public class JobLogController {

    @Autowired
    private JobLogService jobLogService;

    @ApiOperation(value = "列表")
    @GetMapping
    public Pagination<JobLogDO> list(@RequestParam(required = false) String name,
                                     @RequestParam(required = false) String group,
                                     @RequestParam(required = false) LocalDateTime startTime,
                                     @RequestParam(required = false) LocalDateTime endTime,
                                     PageInfo pageInfo) {
        pageInfo.setShowPages(false);
        pageInfo.setLimit(10);
        return jobLogService.find(name, group, startTime, endTime, pageInfo);
    }
}